<template>
  <div>
    <DetailPage v-bind="ExtendFormConfig" :model="formMode" style="width: 100%; margin: 0 auto">
      <template v-slot:ServiceOrgItems="{ row }">
        <ApldTable :columns="row.column" :data="serviceItemData"></ApldTable>
      </template>
    </DetailPage>
  </div>
</template>

<script setup lang="ts">
import { ApldTable } from '@/components/AplidCrud'
import DetailPage from '@/views/aplid/DetailPage/index.vue'
import apiMod from '@/apiMod'
import { ExtendFormConfig } from '../../config'
import { useCommonStore } from '@/stores/common'

const {setLoading} = useCommonStore()
const nowRowData: any = inject('nowRowData')

const formMode = ref({})
const serviceItemData = ref([])
const props = defineProps({
	chainViewInfo:{
		type:Object,
		default:()=>({})
	},
	isBlockchain:{
		type:Boolean,
		default:false
	}
})

const getInitData = () => {
  let query = {
    creditCode: nowRowData.creditCode,
  }
  setLoading()
  Promise.all([apiMod.view_dpServiceOrgExtend_page(query), apiMod.view_dpServiceOrgItems_page(query)])
    .then((res) => {
      return res.map((item) => item.data.records)
    })
    .then((res) => {
      setLoading()
      formMode.value = res[0][0] || {}
      serviceItemData.value = res[1]
    })
}

onMounted(() => {
  if(props.isBlockchain){
    formMode.value = props.chainViewInfo
    serviceItemData.value = props.chainViewInfo.bcServiceOrgItems?JSON.parse(props.chainViewInfo.bcServiceOrgItems):[]
  }else{
    getInitData()
  }
})
</script>

<style scoped></style>
